package cn.ainit.yz.flow;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.ainit.common.ReturnObject;
import cn.ainit.sys.utils.UUID32;
import cn.ainit.yz.flow.entity.YzCheckpiece;


@Controller
@RequestMapping("/yzFlow")
public class YzFlowController {
	
	private YzFlowService yzFlowService;
	@Resource
	public void setYzFlowService(YzFlowService yzFlowService) {
		this.yzFlowService = yzFlowService;
	}
	
	/***
	 * 出片核片的保存
	 * @param yzCheckpiece
	 * @param request
	 * @return
	 * @throws Exception
	 * @author cff
	 * @date 2014-3-25 上午9:15:30
	 */
	@RequestMapping("/saveCheckpiece")
	@ResponseBody
	public ReturnObject saveOrUpAuthorJiaogao(@RequestBody  YzCheckpiece yzCheckpiece,HttpServletRequest request) throws Exception{
		ReturnObject returnObject = new ReturnObject();
		try {
			System.out.println(yzCheckpiece.getFilmMan());
			String checkpieceId = "";
			boolean flag = false;
			if (yzCheckpiece.getCheckpieceId()== null || yzCheckpiece.getCheckpieceId().equals("")) {
				//新添加，保存
				checkpieceId = UUID32.newGuid();
				yzCheckpiece.setCheckpieceId(checkpieceId);
				flag = yzFlowService.saveYzFlow(yzCheckpiece);
				if (flag) {
					returnObject.setMsg("success");
					returnObject.setInfo(checkpieceId);
				}else {
					returnObject.setMsg("fail");
				}
			}else{
				//更新
				flag = yzFlowService.updateYzFlow(yzCheckpiece);
				if (flag) {
					returnObject.setMsg("upsuccess");
				}else {
					returnObject.setMsg("fail");
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			returnObject.setMsg(e.getMessage());
		}
		return returnObject;
	}
	
	

}
